<!DOCTYPE html>
<html>

<head>

</head>

<body>
    <button onclick="reload()">手动重连</button>
    <script src="lib/index.js"></script>
    <script>
        const { createSocket } = mfoSocketControl
        const socketControl = createSocket({
            url: 'ws://127.0.0.1:5500/index.html/ws',
            delay: 15000,
            singleHearBeat() {
                //单次心跳处理的数据
                return JSON.stringify({ code: 200003, data: "", msg: "" })
            },
            beforeHearBeat(err) {
                //心跳开始前
                const token = "";
                const cookieStr = "";
                return JSON.stringify({
                    code: token ? 200008 : 200001,
                    data: token ? { token, cookieStr } : "",
                    msg: "",
                })
            },
            afterReload(err) {
                //重新连接后
                if ([1005, 1006].includes(err.code)) {
                    const token = "";
                    const cookieStr = "";
                    return JSON.stringify({
                        code: token ? 200008 : 200001,
                        data: token ? { token, cookieStr } : "",
                        msg: "",
                    })
                } else {
                    return false;
                }
            },
            messageReceived(message) {
                //消息重构
                console.log(message)
                return message
            },
            reload: true,
            reloadTotal: 10
        })
        console.log(socketControl)
        const reload = () => {
            //手动重连
            socketControl.createReload()
        }
    </script>
</body>

</html>